package com.ott.tool;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.LinkedList;

public class InitMySql implements ActionListener {

	@Override
	public void actionPerformed(ActionEvent e) {
		File file = new File(IndexForm.textArea2.getText());
		if(file.isDirectory()){
			LinkedList<File> list = new LinkedList<File>();
			LinkedList<String> sqllist = new LinkedList<String>();
			File[] files = file.listFiles();
			for (File file2 : files) {
				String fileName=file2.getName();
			    String prefix=fileName.substring(fileName.lastIndexOf(".")+1);
			    if(prefix.equals("war")){
			    	list.add(file2);
			    }else if(prefix.equals("sql")){
			    	sqllist.add(fileName);
			    }
			}
			//执行sql文件
			if(sqllist.size()>0){
				IndexForm.textArea.append("开始执行sql脚本\r\n");
				for (int i = 0; i < sqllist.size(); i++) {
					ScriptRunnerExecSql sres = new ScriptRunnerExecSql();
					sres.execSql(IndexForm.textArea2.getText()+"/"+sqllist.get(i));
				}
				IndexForm.textArea.append("sql脚本执行结束\r\n");
			}else {
				IndexForm.textArea.append("文件夹中不存在sql脚本\r\n");
			}
		}
	}

}
